/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.opgea.token.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.opgea.token.dao.AbstractDAO;
import com.opgea.token.dao.CompanyDAO;
import com.opgea.token.domain.entities.Company;

/**
 * 
 * @author Ramesh
 */
@Repository
public class CompanyDAOImpl extends AbstractDAO<Company> implements CompanyDAO {

    @Autowired
    private SessionFactory sessionFactory;

    @Override
    public Company find(Long id) {
	Query query = sessionFactory.getCurrentSession().createQuery(
		"Select c from Company c where c.id = " + id);
	Company company = (Company) query.uniqueResult();
	return company;
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Company> findAll() {
	List<Company> companies = sessionFactory.getCurrentSession()
		.createQuery("from Company").list();
	return companies;
    }
}
